<template>
  <div>加载中...</div>
</template>
<script>
import { getVisitorLink } from '@/api/visitor'

export default {
  name: '',
  data() {
    return {
      targetUrl: ''
    }
  },
  async mounted() {
    await this.getWxLink()
    window.location.href = this.targetUrl
  },
  methods: {
    async getWxLink() {
      const id = this.$route.params.id
      try {
        const res = await getVisitorLink(id)
        console.log('res --------->', res)
        let url = res?.data?.url
        if (url) {
          if (!url.startsWith('http://') && !url.startsWith('https://')) {
            url = 'http://' + url // 默认添加 http 协议头
          }
          this.targetUrl = url
        }
      } catch (error) {
        throw new Error(error)
      }
    }
  }
}
</script>
<style lang="scss" scoped>
</style>
